/*************************************************************************
 Copyright (C) Unpublished Unis Software, Inc. All rights reserved.
 Unis Software, Inc., Confidential and Proprietary.

 This software is subject to copyright protection
 under the laws of the Public of China and other countries.

 Unless otherwise explicitly stated, this software is provided
 by Unis "AS IS".
 *************************************************************************/
package com.unis.web.account;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.unis.common.ui.jqGrid.GridUIMapper;
import com.unis.common.util.WebUtil;
import com.unis.model.BaseModel;
import com.unis.model.account.SysPermission;
import com.unis.service.account.SysPermissionService;

/**
 * @author CSJ (email:raulcsj@163.com)
 * @since 2012-12-09
 */
@Controller
@RequestMapping("/syspermission")
public class SysPermissionController {

    private SysPermissionService syspermissionService;

    /****************************************
     * Insert a instace of SysPermission
     ****************************************/
    @RequestMapping("/insert")
    @ResponseBody
    public Object insertSysPermission(@RequestBody SysPermission syspermission) throws Exception {
        syspermission.setStatmentId("SysPermission.insert");
        String status = "failure";
        syspermissionService.insert(syspermission);
        status = "success";
        return status;
    }

    /****************************************
     * Update a instace of SysPermission
     ****************************************/
    @RequestMapping("/update")
    @ResponseBody
    public Object update(@RequestBody SysPermission syspermission) throws Exception {
        syspermission.setStatmentId("SysPermission.update");
        String status = "failure";
        syspermissionService.update(syspermission);
        status = "success";
        return status;
    }

    /****************************************
     * Delete a instace of SysPermission
     ****************************************/
    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(@RequestBody SysPermission syspermission) throws Exception {
        syspermission.setStatmentId("SysPermission.delete");
        String status = "failure";
        syspermissionService.batchDelete(syspermission);
        status = "success";
        return status;
    }

    /****************************************
     * Query instaces of SysPermission
     ****************************************/
    @RequestMapping("/queryAsList")
    @ResponseBody
    public Object queryAsList(HttpServletRequest request) throws Exception {
        Map<String, Object> paramMap = WebUtil.getParamsMapFromRequest(request);
        SysPermission syspermission = new SysPermission();
        syspermission.setStatmentId("SysPermission.queryAsList");
        BeanUtils.populate(syspermission, paramMap);
        Map<String, Object> pageMap = GridUIMapper.process(paramMap);
        BeanUtils.populate(syspermission, pageMap);
        List<BaseModel> syspermissionList = syspermissionService.queryAsList(syspermission);
        Map<String, Object> renderMap = GridUIMapper.render(syspermission, syspermissionList);
        return renderMap;
    }

    /****************************************
     * Query a instaces of SysPermission
     ****************************************/
    @RequestMapping("/queryAsObject")
    @ResponseBody
    public BaseModel queryAsObject(@RequestBody SysPermission syspermission) throws Exception {
        syspermission.setStatmentId("SysPermission.queryAsObject");
        return syspermissionService.queryAsObject(syspermission);
    }

    @RequestMapping("/permissionMgr")
    public String permissionMgr() {
        return "sys/syspermissionList";
    }

    @Resource
    public void setSysPermissionService(SysPermissionService syspermissionService) {
        this.syspermissionService = syspermissionService;
    }
}
